home *** CD-ROM | disk | FTP | other *** search
Wrap
'Include the following if not declared in the global module 'Declare Function IsAppLoaded Lib "kernel" Alias "GetModuleHandle" (ByVal N As String) As Integer 'Const TRUE = -1 'Const FALSE = 0 'Const NONE = 0 'Const HOT = 1 'Const COLD = 2 'Constants for Window_State function ' WindowState (form) 'Const NORMAL = 0 ' 0 - Normal 'Const MINIMIZED = 1 ' 1 - Minimized 'Const MAXIMIZED = 2 ' 2 - Maximized 'Variables can be declared in global module and initialized in start up procedure 'Dim nl As String 'nl = chr$(10) + chr$(13) 'new line 'Dim q As String 'q = chr$(34) 'quotation marks 'Dim ProgName As String 'winword filename 'Dim DirName As String 'directory where winword is located Dim chan1 As String 'Stores channel number of winword DDE link Sub Open_Winword_Document (Document As String) 'Opens document, if necessary, and makes it current winword document If IsAppLoaded("MSWord") = FALSE Then xxzz = Shell(ProgName + " " + Document, 3) Else WordMessage$ = "[FileOpen " + q + Document + q + "]" WordMessage$ = WordMessage$ + "[If Not AppMaximize() Then AppMaximize]" End If Execute WordMessage$ End Sub Function Get_Open_Docs (LBox As Control) 'This procedure puts a list of open winword documents 'in the listbox passed as a parameter 'It does not include macros or duplicate windows If IsAppLoaded("MSWord") = FALSE Then Exit Function If TypeOf LBox Is listbox Then If chan1 = "" Then chan1 = Open_Link() NumWins = Val(Get_Info("Str$(CountWindows())")) 'Get number of items on winword window list If NumWins = 0 Then Exit Function'No open windows Get_Open_Docs = NumWins 'Function returns number of open windows For idx = 1 To NumWins temp$ = Get_Info("WindowName$(" + LTrim$(Str$(idx)) + ")") 'ColonPos = InStr(temp$, ":") 'Following lines, if enabled, weed out macros and duplicate windows 'If ColonPos > 2 Then 'If Right$(temp$, 1) = "1" And Len(temp$) = ColonPos + 1 Then 'temp$ = Left$(temp$, ColonPos - 1) 'Else 'temp$ = ""'Must be macro or duplicate window 'End If 'End If If temp$ <> "" Then LBox.AddItem temp$ Next idx End If End Function Function Open_Link () As String 'This function opens a link with winword as client and returns the channel number 'Channel number can be used to cause winword to poke data into VB application If IsAppLoaded("MSWord") = FALSE Then xxzz = Shell(ProgName, 7) mess$ = "[DDEPoke DDEInitiate(" + q + ThisProg + q + "," + q + "DDEForm" + q + "), " mess$ = mess$ + q + "Label1" + q + ", Str$(DDEInitiate(" + q + ThisProg + q + "," mess$ = mess$ + q + "DDEForm" + q + "))]" Execute mess$ Open_Link = DDEForm.Label1.Caption Form1.ChanNum.Caption = Form1.ChanNum.Tag + DDEForm.Label1.Caption 'This statement is included solely for WordDemo and should be disabled for other projects End Function Sub Execute (mess As String) 'Executes a WordBASIC command or string of WordBASIC commands DDEForm.Label1.LinkTopic = "winword|system" DDEForm.Label1.LinkMode = COLD DDEForm.Label1.LinkExecute mess DDEForm.Label1.LinkMode = NONE End Sub Function Get_Info (info As String) As String 'Function returns data obtained from WordBASIC functions If chan1 = "" Then chan1 = Open_Link() mess$ = "[DDEPoke " + chan1 + "," + q + "Label1" + q + ", " + info + "]" Execute mess$ Get_Info = DDEForm.Label1.Caption End Function Sub Close_Link () 'Closes link with winword If IsAppLoaded("MSWord") = FALSE Or chan1 = "" Then Exit Sub DDEMessage$ = "[DDETerminateAll]" Execute DDEMessage$ End Sub Function Is_Doc_Open (FName As String) As Integer 'Function returns the position of an open file on winword window list or -1 if file is not open 'Argument must be full pathname of file to be tested If IsAppLoaded("MSWord") = FALSE Then 'Document cannot be open if winword is not running Is_Doc_Open = -1 Exit Function End If If chan1 = "" Then chan1 = Open_Link() NumWins = Val(Get_Info("Str$(CountWindows())")) 'Get number of items on winword open window list If NumWins = 0 Then 'No documents are open Is_Doc_Open = -1 Exit Function End If FName = UCase$(FName) 'Open documents are listed in upper case on winword open window list WordDir$ = Get_Info("Files$(" + q + "." + q + ")") 'Get current winword directory For idx = 1 To NumWins TestFile$ = Get_Info("WindowName$(" + LTrim$(Str$(idx)) + ")") ColonPos = InStr(TestFile$, ":") If ColonPos = 2 Then DLetter$ = Left$(TestFile$, 2) 'File is on a different drive from current winword directory TestFile$ = Right$(TestFile$, Len(TestFile$) - 2) ColonPos = InStr(TestFile$, ":") Else DLetter$ = Left$(WordDir$, 2) 'File is on same drive as current winword directory End If If ColonPos > 0 Then 'Must be a macro or duplicate window If Val(Right$(TestFile$, 1)) < 9 And Len(TestFile$) = ColonPos + 1 Then TestFile$ = Left$(TestFile$, ColonPos - 1) End If End If If InStr(TestFile$, "\") = 1 Then 'Build full filename TestFile$ = DLetter$ + TestFile$ 'Add drive if document is not in current directory or subdirectory of current directory Else TestFile$ = Build_Full_Name(WordDir$, TestFile$) End If If FName = TestFile$ Then Is_Doc_Open = idx Exit Function End If Next idx Is_Doc_Open = -1 End Function Function Build_Full_Name (DName As String, FName As String) As String If Right$(DName, 1) <> "\" And Left$(FName, 1) <> "\" Then Build_Full_Name = DName + "\" + FName ElseIf Right$(DName, 1) = "\" And Left$(FName, 1) = "\" Then Build_Full_Name = Left$(DName, Len(DName) - 1) + FName Else Build_Full_Name = DName + FName End If End Function Function Winword_State () As Integer If Val(Get_Info("Str$(AppMaximize())")) = 0 Then If Val(Get_Info("Str$(AppMinimize())")) = 0 Then Winword_State = NORMAL 'The Winword window is in the normal state Else Winword_State = MINIMIZED 'Winword is minimized End If Else Winword_State = MAXIMIZED 'Winword is maximized End If End Function Sub Create_Document (template As String) 'Creates a new document based on template; document can read DDE info from VB forms If IsAppLoaded("MSWord") = FALSE Then xxzz = Shell(ProgName, 3) End If DDEMessage$ = "[If NOT AppMaximize() Then AppMaximize]" DDEMessage$ = DDEMessage$ + "[FileNew.Template=" + q + template + q + "]" DDEMessage$ = DDEMessage$ + "[EditSelectAll][UpdateFields][LockFields]" DDEMessage$ = DDEMessage$ + "[StartOfDocument]" Execute DDEMessage$ End Sub Function Get_Winword_Directory () As String If Is_File_Name("d:\winword\winword.ini") Then Get_Winword_Directory = "d:\winword" ElseIf Is_File_Name("c:\winword\winword.ini") Then Get_Winword_Directory = "c:\winword" Else Get_Winword_Directory = InputBox$("Please type full pathname for winword directory") End If End Function Function Is_File_Name (FName As String) 'This function requires appropriate type and API declarations in the global module Dim TheStruct As OfStruct ' used to test for open files xxzz% = OpenFile(FName, TheStruct, OF_EXIST) zzxx% = lclose(xxzz%) If xxzz% > 0 Then Is_File_Name = TRUE Else Is_File_Name = FALSE End If End Function